package com.threaddemo3;

import java.util.concurrent.*;

public class CallableDemo3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //用法

        //2、放到线程池中 使用线程池配合使用
        ExecutorService es = Executors.newSingleThreadExecutor();

        //3、将Callable 实例提交到线程池中
        Future future = es.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println("执行Runnable...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        Object ret =  future.get();

        System.out.println("ret = " + ret);

        //5、关闭 ExecutorService
        es.shutdown();
    }
}
